home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 418_04 / rasmol.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-02  |  21.3 KB  |  797 lines

  1. /* rasmol.c
  2.  * RasMol2 Molecular Graphics
  3.  * Roger Sayle, February 1994
  4.  * Version 2.3
  5.  */
  6.  
  7. #ifndef sun386
  8. #include <stdlib.h>
  9. #endif
  10. #include <signal.h>
  11. #include <stdio.h>
  12. #include <math.h>
  13.  
  14. #include "rasmol.h"
  15. #include "graphics.h"
  16. #include "molecule.h"
  17. #include "transfor.h"
  18. #include "command.h"
  19. #include "abstree.h"
  20. #include "render.h"
  21. #include "pixutils.h"
  22. #include "outfile.h"
  23.  
  24. #ifdef TERMIOS
  25. #include <sys/types.h>
  26. #include <sys/time.h>
  27.  
  28. #ifdef esv
  29. #include <sysv/sys/termio.h>
  30. #include <sysv/unistd.h>
  31. #else
  32. #include <sys/termio.h>
  33. #include <unistd.h>
  34. #endif
  35.  
  36. #if defined(_SEQUENT_) || defined(_AIX)
  37. #include <sys/select.h>
  38. #endif
  39. #endif /* TERMIOS */
  40.  
  41. #ifdef VMS
  42. #include <tt2def.h>
  43. #include <iodef.h>
  44. #endif
  45.  
  46.  
  47. #define TwoPi    6.2832
  48.  
  49.  
  50. #define MainMenuSize  6
  51. static char *MainMenu[] = { "Load","Display","Colours",
  52.                             "Options","Export","Quit" };
  53. #define DispMenuSize  7
  54. static char *DispMenu[] = { "Wireframe","Backbone","Sticks","Spacefill",
  55.                             "Ball & Stick", "Ribbons", "Cancel" };
  56.  
  57. #define ColrMenuSize  8
  58. static char *ColrMenu[] = { "Mono","CPK","Shapely","Group", "Chain",
  59.                             "Temperature","Structure", "Cancel" };
  60. #define OptnMenuSize  6
  61. static char *OptnMenu[] = { "Slab Mode","Hydrogen","Het Atoms",
  62.                             "Specular","Shadow","Cancel" };
  63. #define SaveMenuSize  5
  64. static char *SaveMenu[] = { "GIF","EPSF","PPM","Rast","Cancel" };
  65.  
  66. #define ConfMenuSize  2
  67. static char *ConfMenu[] = { "Confirm", "Cancel" };
  68.  
  69.  
  70. #ifdef VMS
  71. static struct {
  72.         unsigned short size; 
  73.         unsigned short type;
  74.         char *string;
  75.         } StdInDesc = { 10, 0, "SYS$INPUT:" };
  76.  
  77. /* Character Terminator Mask! */
  78. static int StdInMask[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  79.  
  80. static short StdInBlck[4];
  81. static int StdInMode[3];
  82. static int StdInOrig[3];
  83. static short StdInChan;
  84. static int StdInStatus;
  85. static char StdInChar;
  86. static int StdInFlag;
  87. #endif
  88.  
  89. #ifdef TERMIOS
  90. static struct fd_set WaitSet;
  91. static struct timeval TimeOut;
  92. static struct termio OrigTerm;
  93. static struct termio IntrTerm;
  94. static int SocketNo,FileNo;
  95. #endif
  96.  
  97. static char fnamebuf[128];
  98. static char *FileNamePtr;
  99. static int ProfCount;
  100. static int LexState;
  101. static int State;
  102.  
  103.  
  104. #ifdef __STDC__
  105. /* Function Prototype */
  106. int HandleEvents( int );
  107. #endif
  108.  
  109.  
  110. void WriteChar( ch )
  111.     char ch;
  112. {   putc(ch,stderr);
  113. }
  114.  
  115. void WriteString( ptr )
  116.     char *ptr;
  117. {   fputs(ptr,stderr);
  118. }
  119.  
  120.  
  121. #ifdef VMS
  122. static int StdInASTEvent()
  123. {
  124.     register int ch;
  125.     register int i;
  126.  
  127.     if( !StdInFlag )
  128.         return( False );
  129.  
  130.     if( StdInBlck[0] & 0x01 )
  131.     {   if( StdInBlck[1] )
  132.         {   if( (StdInChar==0x03) || (StdInChar==0x1a) )
  133.                 RasMolFatalExit("*** Quit ***");
  134.  
  135.             if( LexState == 0 )
  136.             {   if( StdInChar == 0x1b )
  137.                 {   LexState = 1;  ch = 0;
  138.                 } else ch = StdInChar;
  139.  
  140.             } else if( LexState == 1 )
  141.             {   if( StdInChar == '[' )
  142.                 {   LexState = 2;  ch = 0;
  143.                 } else if( StdInChar != 0x1b )
  144.                 {   LexState = 0;  ch = StdInChar;
  145.                 } else ch = 0;
  146.  
  147.             } else /* LexState == 2 */
  148.             {   LexState = 0;
  149.                 switch( StdInChar )
  150.                 {   case('A'): ch = 0x10;  break;
  151.                     case('B'): ch = 0x0e;  break;
  152.                     case('C'): ch = 0x06;  break;
  153.                     case('D'): ch = 0x02;  break;
  154.                     default:   ProcessCharacter('[');
  155.                                if( StdInChar == 0x1b )
  156.                                {   LexState = 1;  ch = 0;
  157.                                } else ch = StdInChar;
  158.                 }
  159.             }
  160.         } else ch = '\n';
  161.  
  162.         if( ch && ProcessCharacter(ch) )
  163.         {   if( ProcessCommand() )
  164.                 RasMolExit();
  165.  
  166.             if( !CommandActive )
  167.                 ResetCommandLine(0);
  168.         }
  169.     }
  170.  
  171.     /* Queue an Asynchronous I/O Request */
  172.     StdInStatus = sys$qio( 0, StdInChan, IO$_READVBLK|IO$M_NOECHO, 
  173.                            StdInBlck, StdInASTEvent, 0, &StdInChar, 
  174.                            1, 0, StdInMask, 0, 0);
  175.     return( True );
  176. }
  177. #endif
  178.  
  179.  
  180. void InitTerminal(socket)
  181.     int socket;
  182. {
  183. #ifdef SIGTTIN
  184.     signal(SIGTTIN,SIG_IGN);
  185. #endif
  186. #ifdef SIGTTOU
  187.     signal(SIGTTOU,SIG_IGN);
  188. #endif
  189.  
  190. #ifdef TERMIOS
  191.     FileNo = fileno(stdin);
  192.     SocketNo = socket;
  193.     FD_ZERO(&WaitSet);
  194.  
  195.     if( isatty(FileNo) )
  196.     {   ioctl(FileNo, TCGETA, &OrigTerm);
  197.         IntrTerm = OrigTerm;
  198.  
  199.         IntrTerm.c_iflag |= IGNBRK|IGNPAR;
  200.         IntrTerm.c_iflag &= ~(BRKINT|PARMRK|INPCK|IXON|IXOFF);
  201.         IntrTerm.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|NOFLSH);
  202.         IntrTerm.c_lflag |= ISIG;
  203.  
  204.         IntrTerm.c_cc[VMIN] = 1;
  205.         IntrTerm.c_cc[VTIME] = 0;
  206.  
  207. #ifdef VSUSP /* Disable ^Z */
  208.         IntrTerm.c_cc[VSUSP] = 0;
  209. #endif
  210.  
  211.         ioctl(FileNo, TCSETAW, &IntrTerm);
  212.     }
  213. #endif /* TERMIOS */
  214.  
  215. #ifdef VMS
  216.     /* Associate "SYS$INPUT" with channel StdInChan! */
  217.     StdInStatus = sys$assign(&StdInDesc, &StdInChan, 0, 0, 0);
  218.     if( StdInStatus & 0x01 )
  219.     {   StdInFlag = True;
  220.  
  221.         /* Determine Original Terminal Mode */
  222.         sys$qiow( 0, StdInChan, IO$_SENSEMODE, 0, 0, 0,
  223.                   StdInOrig, 12, 0, 0, 0, 0 );
  224.  
  225.         StdInMode[0] = StdInOrig[0];
  226.         StdInMode[1] = StdInOrig[1];
  227.         StdInMode[2] = StdInOrig[2];
  228.  
  229.         /* Select "RAW" Terminal Mode */
  230.         StdInMode[2] |= TT2$M_PASTHRU;
  231.  
  232.         /* Set Current Terminal Mode */
  233.         sys$qiow( 0, StdInChan, IO$_SETMODE, 0, 0, 0,
  234.                   StdInMode, 12, 0, 0, 0, 0 );
  235.  
  236.         /* Queue an Asynchronous I/O Request */
  237.         StdInStatus = sys$qio( 0, StdInChan, IO$_READVBLK|IO$M_NOECHO, 
  238.                                StdInBlck, StdInASTEvent, 0, &StdInChar, 
  239.                                1, 0, StdInMask, 0, 0);
  240.     } else StdInFlag = False;
  241. #endif
  242.  
  243.     setbuf(stdin,(char*)NULL);
  244. }
  245.  
  246.  
  247. void ResetTerminal()
  248. {
  249. #ifdef TERMIOS
  250.     if( isatty(FileNo) )
  251.         ioctl(FileNo, TCSETAW, &OrigTerm);
  252. #endif
  253.  
  254. #ifdef VMS
  255.     StdInFlag = False;
  256.     if( StdInStatus & 0x01 )
  257.         sys$cancel(StdInChan);
  258.  
  259.     sys$qiow( 0, StdInChan, IO$_SETMODE, 0, 0, 0,
  260.               StdInOrig, 12, 0, 0, 0, 0 );
  261. #endif
  262. }
  263.  
  264.  
  265. static int FetchCharacter()
  266. {
  267. #ifdef TERMIOS
  268.     register int status;
  269.     register int width;
  270.  
  271.     if( SocketNo )
  272.         do {
  273.             if( !CommandActive )
  274.                 ResetCommandLine(0);
  275.             if( HandleEvents(False) )
  276.                 RasMolExit();
  277.  
  278.             /* To avoid slow response time */
  279.             if( !CommandActive )
  280.                 ResetCommandLine(0);
  281.  
  282.             FD_SET(FileNo,&WaitSet);
  283.             FD_SET(SocketNo,&WaitSet);
  284.             TimeOut.tv_usec = 0;
  285.             TimeOut.tv_sec = 1;
  286.  
  287.             width = MaxFun(FileNo,SocketNo)+1;
  288.             status = select( width, &WaitSet,
  289.                      (struct fd_set*)NULL, (struct fd_set*)NULL, &TimeOut );
  290.         } while( (status<1) || !FD_ISSET(FileNo,&WaitSet) );
  291. #endif /* TERMIOS */
  292.  
  293.     if( !CommandActive )
  294.         ResetCommandLine(0);
  295.     return( getc(stdin) );
  296. }
  297.  
  298. static int ReadCharacter()
  299. {
  300.     register int ch;
  301.  
  302.     if( LexState )
  303.     {   ch = LexState;
  304.         LexState = 0;
  305.         return( ch );
  306.     }
  307.  
  308.     ch = FetchCharacter();
  309.     if( ch!=0x1b ) return( ch );
  310.     ch = FetchCharacter();
  311.     if( ch!='[' ) return( ch );
  312.  
  313.     switch( ch=FetchCharacter() )
  314.     {   case('A'): return( 0x10 );
  315.         case('B'): return( 0x0e );
  316.         case('C'): return( 0x06 );
  317.         case('D'): return( 0x02 );
  318.     }
  319.     LexState = ch;
  320.     return('[');
  321. }
  322.  
  323.  
  324. void RasMolExit()
  325. {
  326.     WriteChar('\n');
  327.     if( CommandActive )
  328.         WriteChar('\n');
  329.  
  330.     if( Interactive )
  331.         CloseDisplay();
  332.     ResetTerminal();
  333.     exit(0);
  334. }
  335.  
  336.  
  337. void RasMolFatalExit( msg )
  338.     char *msg;
  339. {
  340.     WriteChar('\n');
  341.     WriteString(msg);
  342.     WriteChar('\n');
  343.     WriteChar(0x07);
  344.  
  345.     if( Interactive )
  346.         CloseDisplay();
  347.     ResetTerminal();
  348.     exit(1);
  349. }
  350.  
  351.  
  352. void RasMolSignalExit()
  353. {
  354.     RasMolFatalExit("*** Quit ***");
  355. }
  356.  
  357.  
  358. static void LoadInitFile()
  359. {
  360.     register char *src,*dst;
  361.     register FILE *initrc;
  362.     register char *fname;
  363.  
  364.     fname = ".rasmolrc";
  365.     initrc = fopen(fname,"r");
  366.     if( !initrc && (src=(char*)getenv("HOME")) )
  367.     {   dst = fnamebuf; 
  368.         while( *src )
  369.             *dst++ = *src++;
  370.         *dst++ = '/';
  371.  
  372.         src = fname; fname = fnamebuf;
  373.         while( (*dst++ = *src++) );
  374.         initrc = fopen(fname,"r");
  375.     }
  376.  
  377.     if( !initrc && (src=(char*)getenv("RASMOLPATH")) )
  378.     {   dst = fnamebuf; 
  379.         while( *src )
  380.             *dst++ = *src++;
  381.         *dst++ = '/';
  382.  
  383.         src = "rasmolrc"; fname = fnamebuf;
  384.         while( (*dst++ = *src++) );
  385.         initrc = fopen(fname,"r");
  386.     }
  387.  
  388.     if( initrc )
  389.         LoadScriptFile(initrc,fname);
  390. }
  391.  
  392.  
  393. static void HandleMenu( option )
  394.      int option;
  395. {
  396.     register int mask;
  397.  
  398.     switch( State )
  399.     {   /* Main Menu */
  400.         case(1):  if( !option )
  401.                   {   if( !Database )
  402.                           ResetCommandLine(2);
  403.                       break;
  404.                   } else State = option+1;
  405.  
  406.                   switch(State)
  407.                   {   case(1): NewMenu(MainMenuSize,MainMenu); break;
  408.                       case(2): NewMenu(DispMenuSize,DispMenu); break;
  409.                       case(3): NewMenu(ColrMenuSize,ColrMenu); break;
  410.                       case(4): NewMenu(OptnMenuSize,OptnMenu); break;
  411.                       case(5): NewMenu(SaveMenuSize,SaveMenu); break;
  412.                       case(6): NewMenu(ConfMenuSize,ConfMenu); break;
  413.                   }
  414.                   break;
  415.  
  416.         /* Display Menu */
  417.         case(2):  switch( option )
  418.                   {   case(0):  DisableSpacefill();
  419.                                 EnableWireFrame(True,0);
  420.                                 SetRibbonStatus(False,0);
  421.                                 DisableBackBone();
  422.                                 break;
  423.  
  424.                       case(1):  DisableSpacefill();
  425.                                 DisableWireFrame();
  426.                                 SetRibbonStatus(False,0);
  427.                                 EnableBackBone(False,80);
  428.                                 break;
  429.  
  430.                       case(2):  DisableSpacefill();
  431.                                 EnableWireFrame(False,80);
  432.                                 SetRibbonStatus(False,0);
  433.                                 DisableBackBone();
  434.                                 break;
  435.  
  436.                       case(3):  SetVanWaalRadius();
  437.                                 DisableWireFrame();
  438.                                 SetRibbonStatus(False,0);
  439.                                 DisableBackBone();
  440.                                 break;
  441.  
  442.                       case(4):  SetRadiusValue(120);
  443.                                 EnableWireFrame(False,40);
  444.                                 SetRibbonStatus(False,0);
  445.                                 DisableBackBone();
  446.                                 break;
  447.  
  448.                       case(5):  DisableSpacefill();
  449.                                 DisableWireFrame();
  450.                                 SetRibbonStatus(True,0);
  451.                                 DisableBackBone();
  452.                   }
  453.  
  454.                   if( option != 6 )
  455.                       ReDrawFlag |= RFRefresh;
  456.                   NewMenu(MainMenuSize,MainMenu);
  457.                   State = 1;  break;
  458.  
  459.         /* Colour Menu */
  460.         case(3):  if( option != 7 )
  461.                   {   switch( option )
  462.                       {   case(0): MonoColourAttrib(255,255,255);  break;
  463.                           case(1): CPKColourAttrib();              break;
  464.                           case(2): ShapelyColourAttrib();          break;
  465.                           case(3): ScaleColourAttrib(GroupAttr);   break;
  466.                           case(4): ScaleColourAttrib(ChainAttr);   break;
  467.                           case(5): ScaleColourAttrib(TempAttr);    break;
  468.                           case(6): StructColourAttrib();           break;
  469.                       }
  470.                       ReDrawFlag |= RFColour;
  471.                   }
  472.  
  473.                   NewMenu(MainMenuSize,MainMenu);
  474.                   State = 1;  break;
  475.  
  476.         /* Option Menu */
  477.         case(4):  switch( option )
  478.                   {   case(0):  UseSlabPlane = !UseSlabPlane;
  479.                                 if( UseSlabPlane )
  480.                                     UseShadow = False;
  481.                                 break;
  482.  
  483.                       case(1):  mask = NormAtomFlag;
  484.                                 if( HetaGroups )
  485.                                     mask |= HeteroFlag;
  486.                                 CommandActive = False;
  487.                                 Hydrogens = !Hydrogens;
  488.  
  489.                                 if( Hydrogens )
  490.                                 {   fputs("\nHydrogens included!\n",stderr);
  491.                                     SelectZone(mask|HydrogenFlag);
  492.                                 } else 
  493.                                 {   fputs("\nHydrogens removed!\n",stderr);
  494.                                     RestrictZone(mask);
  495.                                 } break;
  496.  
  497.                       case(2):  mask = NormAtomFlag;
  498.                                 if( Hydrogens )
  499.                                     mask |= HydrogenFlag;
  500.                                 CommandActive = False;
  501.                                 HetaGroups = !HetaGroups;
  502.  
  503.                                 if( HetaGroups )
  504.                                 {   fputs("\nHETA atoms selected!\n",stderr);
  505.                                     SelectZone(mask|HeteroFlag);
  506.                                 } else 
  507.                                 {   fputs("\nHETA atoms removed!\n",stderr);
  508.                                     RestrictZone(mask);
  509.                                 } break;
  510.  
  511.                       case(3):  FakeSpecular = !FakeSpecular;
  512.                                 ReDrawFlag |= RFColour;
  513.                                 break;
  514.  
  515.                       case(4):  UseShadow = !UseShadow;
  516.                                 if( UseShadow )
  517.                                 {   ReviseInvMatrix();
  518.                                     VoxelsClean = False;
  519.                                     UseSlabPlane = False;
  520.                                     ReAllocBuffers();
  521.                                 }
  522.                                 break;
  523.  
  524.                   }
  525.  
  526.                   if( option != 5 )
  527.                       ReDrawFlag |= RFRefresh;
  528.                   NewMenu(MainMenuSize,MainMenu);
  529.                   State = 1;  break;
  530.  
  531.         /* Save Menu */
  532.         case(5):  if( option==4 )
  533.                   {   NewMenu(MainMenuSize,MainMenu);
  534.                       State = 1;
  535.                   } else
  536.                   {   ResetCommandLine(3);
  537.                       StateOption = option;
  538.                   }
  539.                   break;
  540.  
  541.         /* Quit Menu */
  542.         case(6):  if( !option )
  543.                       RasMolExit();
  544.                   NewMenu(MainMenuSize,MainMenu);
  545.                   State = 1;  break;
  546.     }
  547. }
  548.  
  549.  
  550. void RefreshScreen()
  551. {
  552.     if( !UseSlabPlane )
  553.     {   ReDrawFlag &= ~(RFTransZ|RFSlab|RFPoint);
  554.     } else ReDrawFlag &= ~(RFTransZ|RFPoint);
  555.  
  556.     if( ReDrawFlag )
  557.     {   if( ReDrawFlag & RFReSize )
  558.             ReSizeScreen();
  559.  
  560.         if( ReDrawFlag & RFColour )
  561.         {   if( Interactive ) 
  562.                 ClearImage();
  563.             DefineColourMap();
  564.         }
  565.  
  566.         if( Database )
  567.         {   if( Interactive )
  568.                 BeginWait();
  569.             if( ReDrawFlag & RFApply ) 
  570.                 ApplyTransform();
  571.             DrawFrame();
  572.             if( Interactive )
  573.             {   TransferImage();
  574.                 EndWait();
  575.             }
  576.         } else if( Interactive )
  577.         {   ClearBuffers();
  578.             TransferImage();
  579.         }
  580.         ReDrawFlag = 0;
  581.     }
  582. }
  583.  
  584.  
  585. void AdviseUpdate( item )
  586.     int item;
  587. {
  588. }
  589.  
  590.  
  591. static int ProcessCommand()
  592. {
  593.     switch(CurState)
  594.     {    case(1):  /* RasMol Prompt */
  595.                    return( ExecuteCommand() );
  596.  
  597.          case(2):  /* PDB Filename */
  598.                    if( *CurLine && FetchFile(FormatPDB,False,CurLine) )
  599.                    {   ReDrawFlag |= RFRefresh | RFColour;
  600.                        if( InfoBondCount < 1 )
  601.                        {   EnableBackBone(False,80);
  602.                        } else EnableWireFrame(True,0);
  603.                        CPKColourAttrib();
  604.                    }
  605.                    NewMenu(MainMenuSize,MainMenu);
  606.                    ResetCommandLine(1);
  607.                    State = 1;
  608.                    break;
  609.  
  610.          case(3):  /* Output Filename */
  611.                    if( *CurLine ) switch( StateOption )
  612.                    {   case(0):   WriteGIFFile(CurLine);            break;
  613.                        case(1):   WriteEPSFFile(CurLine,True,True); break;
  614.                        case(2):   WritePPMFile(CurLine,True);       break;
  615.                        case(3):   WriteRastFile(CurLine,True);      break;
  616.                    }
  617.                    NewMenu(MainMenuSize,MainMenu);
  618.                    ResetCommandLine(1);
  619.                    State = 1;
  620.                    break;
  621.     }
  622.     return( False );
  623. }
  624.  
  625.  
  626. int HandleEvents( wait )
  627.     int wait;
  628. {
  629.     register int result;
  630.  
  631.     result = FetchEvent( wait );
  632.     while( ReDrawFlag || result )
  633.     {   if( result )
  634.         {   if( result>0 )
  635.             {   if( ProcessCharacter(result) )
  636.                     if( ProcessCommand() )
  637.                         return( True );
  638.             } else if ( CurState==1 )
  639.                 HandleMenu( result+ButMax );
  640.         } else
  641.         {   if( ReDrawFlag&RFPoint )
  642.             {   if( Database )
  643.                     IdentifyAtom(PointX,PointY);
  644.                 ReDrawFlag &= ~RFPoint;
  645.             }
  646.             if( ReDrawFlag )
  647.                 RefreshScreen();
  648.         }
  649.         result = FetchEvent( False );
  650.     }
  651.     return( False );
  652. }
  653.  
  654.  
  655. #ifdef PROFILE
  656. static void ProfileExecution()
  657. {
  658.     register int start,stop;
  659.     register Real delta;
  660.     register int i;
  661.  
  662.     delta = TwoPi/ProfCount;
  663.  
  664.     start = time((long*)NULL);
  665.     for( i=0; i<ProfCount; i++ )
  666.     {   DrawFrame();
  667.         if( Interactive )
  668.             TransferImage();
  669.         ReDrawFlag = RFRotateY;
  670.         DialValue[1] += delta;
  671.         /* UpdateScrollBars(); */
  672.         ApplyTransform();
  673.     }
  674.  
  675.     stop = time((long*)NULL);
  676.     fprintf(stderr,"Execution of %d frames\n",ProfCount);
  677.     fprintf(stderr,"Duration = %ld seconds\n",stop-start);
  678.     RasMolExit();
  679. }
  680. #endif /* PROFILE */
  681.  
  682. static void DisplayUsage()
  683. {
  684.     fputs("usage: rasmol [file]\n",stderr);
  685.     putc('\n',stderr);
  686.     exit(1);
  687. }
  688.  
  689.     
  690. static void ProcessOptions(argc,argv)
  691.     int argc;  char *argv[];
  692. {
  693.     register char *ptr;
  694.     register int i;
  695.  
  696.     for( i=1; i<argc; i++ )
  697.     {   ptr = argv[i];
  698.         if( *ptr == '-' )
  699.         {
  700.         } else
  701.             if( !FileNamePtr )
  702.             {   FileNamePtr = ptr;
  703.             } else DisplayUsage();
  704.     }
  705. }
  706.  
  707.  
  708. int main(argc,argv)
  709. int argc; char *argv[];
  710. {
  711.     register char ch;
  712.  
  713.     FakeSpecular = False; SpecPower = 8;
  714.     FileNamePtr = NULL;   ProfCount = 0;
  715.  
  716.     ProcessOptions(argc,argv);
  717.     ReDrawFlag = 0;
  718. #ifdef PROFILE
  719.     ProfCount = 10;
  720. #endif
  721.     
  722.     setbuf(stderr,(char *)NULL);
  723.     if( (Interactive=OpenDisplay(CanvWidth,CanvHeight)) )
  724.         NewMenu(MainMenuSize,MainMenu);
  725.     InitTerminal(Interactive);
  726.     signal(SIGINT,RasMolSignalExit);
  727.  
  728.  
  729.     fputs("RasMol Molecular Renderer\n",stderr);
  730.     fputs("Roger Sayle, February 1994\n",stderr);
  731.     fputs("Version 2.3\n",              stderr);
  732.  
  733. #ifdef EIGHTBIT
  734.     fputs("[8bit version]\n\n",  stderr);
  735. #else
  736.     fputs("[24bit version]\n\n", stderr);
  737. #endif
  738.  
  739.     if( !Interactive )
  740.         fputs("No suitable display detected!\n",stderr);
  741.  
  742.     InitialiseCommand();
  743.     InitialiseTransform();
  744.     InitialiseDatabase();
  745.     InitialiseRenderer();
  746.     InitialisePixUtils();
  747.     InitialiseAbstree();
  748.     InitialiseOutFile();
  749.  
  750.     LoadInitFile();
  751.  
  752. #ifdef PROFILE
  753.     if( ProfCount )
  754.     {   UseShadow = True;
  755.         if( !FileNamePtr && !FetchFile(FormatPDB,True,FileNamePtr) )
  756.             RasMolFatalExit("Profile Error: Invalid PDB file name!");
  757.  
  758.         SetVanWaalRadius();
  759.         CPKColourAttrib();
  760.         DefineColourMap();
  761.         if( Interactive ) 
  762.             FetchEvent(False);
  763.         ProfileExecution();
  764.     }
  765. #endif
  766.  
  767.     if( FileNamePtr && FetchFile(FormatPDB,True,FileNamePtr) )
  768.     {   ReDrawFlag |= RFRefresh | RFColour;
  769.         if( InfoBondCount < 1 )
  770.         {   EnableBackBone(False,80);
  771.         } else EnableWireFrame(True,0);
  772.         CPKColourAttrib();
  773.         RefreshScreen();
  774.     }
  775.  
  776.     State = 1;
  777.     LexState = 0;
  778.     ResetCommandLine(1);
  779.  
  780. #ifndef TERMIOS
  781.     if( Interactive )
  782.     {   while( !HandleEvents(True) )
  783.             if( !CommandActive )
  784.                 ResetCommandLine(0);
  785.     } else
  786. #endif
  787.     while( True )
  788.     {   ch = ReadCharacter();
  789.         if( ProcessCharacter(ch) )
  790.             if( ProcessCommand() )
  791.                 break;
  792.         RefreshScreen();
  793.     }
  794.     RasMolExit();
  795.     return( 0 );
  796. }
  797.